package com.ruoyi.system.dto.convert;

import com.ruoyi.system.dto.StageAddDTO;
import com.ruoyi.system.dto.StageUpdateDTO;
import com.ruoyi.system.entity.ConstructionProjectStageRelDO;
import com.ruoyi.system.entity.ConstructionStageDO;
import com.ruoyi.system.vo.StageDetailVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 施工阶段类型转换器（DTO ↔ DO）
 */
@Mapper(componentModel = "spring")
public interface StageConverter {

    StageConverter INSTANCE = Mappers.getMapper(StageConverter.class);

    /**
     * 新增DTO 转 DO（自定义阶段，忽略自动生成字段）
     */
    @Mappings({
            @Mapping(target = "id", ignore = true),
            @Mapping(target = "stageCode", ignore = true),
            @Mapping(target = "stageType", constant = "2"), // 固定为自定义阶段（2）
            @Mapping(target = "designerId", ignore = true),
            @Mapping(target = "createBy", ignore = true),
            @Mapping(target = "createTime", ignore = true),
            @Mapping(target = "updateBy", ignore = true),
            @Mapping(target = "updateTime", ignore = true),
            @Mapping(target = "isDeleted", ignore = true)
    })
    ConstructionStageDO addDtoToDo(StageAddDTO dto);

    /**
     * 修改DTO 转 DO（忽略不可修改字段）
     */
    @Mappings({
            @Mapping(target = "stageCode", ignore = true),
            @Mapping(target = "stageType", ignore = true),
            @Mapping(target = "designerId", ignore = true),
            @Mapping(target = "createBy", ignore = true),
            @Mapping(target = "createTime", ignore = true),
            @Mapping(target = "updateTime", ignore = true),
            @Mapping(target = "isDeleted", ignore = true)
    })
    ConstructionStageDO updateDtoToDo(StageUpdateDTO dto);

    /**
     * DO 转 修改DTO（用于回显数据）
     */
    StageUpdateDTO doToUpdateDto(ConstructionStageDO stageDO);

    /**
     * DO列表 转 修改DTO列表
     */
    List<StageUpdateDTO> doListToUpdateDtoList(List<ConstructionStageDO> stageDOList);

    /**
     * DO列表 转 修改DTO列表
     */
    List<StageDetailVO> doListToVOList(List<ConstructionProjectStageRelDO> stageDOList);
}